<template>
  <div class="app-container">

    <el-row :gutter="10">
      <el-col :span="4" >
        <el-input
          @clear="search"
          placeholder="请输入产品名称"
          v-model="PageDto.name"
          clearable
        >
        </el-input>
      </el-col>
      <el-col :span="4" >
        <el-input
          @clear="search"
          placeholder="请输入用户名"
          v-model="PageDto.username"
          clearable
        >
        </el-input>
      </el-col>
      <el-col :span="4" >
        <el-input
          @clear="search"
          placeholder="请输入产品标识"
          v-model="PageDto.productKey"
          clearable
        >
        </el-input>
      </el-col>
        <el-col :span="4">
          <el-select @clear="clearareaName" v-model="PageDto.areaCode" clearable filterable placeholder="请选择行政区">
              <el-option
                v-for="item in areaList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
            </el-option>
          </el-select>
        </el-col>
      <el-col :span="2">
            <el-button @click="PageDto.now=1;search()" type="primary" icon="el-icon-search">搜索</el-button>
        </el-col>
         <el-col :span="2">
            <el-button @click="clearSearch" type="danger" icon="el-icon-delete">清空</el-button>
        </el-col>
    </el-row>


    <el-table :data="List" stripe style="width: 100%" fit>
      <el-table-column prop="name" label="产品名称" align="center"/>
      <el-table-column prop="tenantName" label="所属租户" align="center"/>
      <el-table-column prop="areaName" label="行政区" align="center"/>
      <el-table-column prop="username" label="用户名" align="center" width="300"/>
      <el-table-column prop="productKey" label="产品标识key" align="center" width="300"/>
    </el-table>
    <br />
    <!-- <el-pagination
      style="float: right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageDto.now"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageDto.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination> -->
    <!-- 分页组件 -->
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="PageDto.now"
      layout="total,prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>

//导入dept api
import { page} from "@/api/product";
import {all} from "@/api/area";
//导入pcd组件
// import PCD  from '../components/pcd.vue';
export default {
  components: {
    // // PCD:PCD
    // PCD
  },
  data() {
    return {
      List: [],
      PageDto: {
        now: 1,
        size: 10,
        name: "",
        username: "",
        productKey: "",
        areaCode: "",
      },
      areaList: [],
      pages: 0,
      total: 0,
    };
  },
  methods: {
    handleCurrentChange(now) {
      this.PageDto.now = now;
      this.search();
    },
    search() {
      page(this.PageDto).then((res) => {
        this.List = res.list;
        this.pages = res.pages;
        this.total = res.total;
      });
      all().then(res=>{
        this.areaList = res.data
      })
    },
    clearSearch() {
      this.PageDto.name = "";
      this.PageDto.username = "";
      this.PageDto.productKey = "";
      this.PageDto.areaCode = "";
      this.search();
    },
    clearareaName(){
      this.PageDto.areaCode = ""
      this.search()
    },
    // switchEnable(tenantId){
    //   toggleEnable(tenantId).then(res=>{
    //     if(res.ok)
    //       this.search()
    //   })
    // }
  },
  created() {
    this.search();
  },
};
</script>